package cn.itcast.mq.listener;

import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
public class SpringRabbitListener {
//    @RabbitListener(queues = "simple.queue")
//    public void listenSimpleQueue(String msg) {
//        System.out.println("消费者接收到simple.queue的消息：【" + msg + "】");
//        System.err.println(1 / 0);
//        System.err.println("消费者处理消息成功!");
//    }


    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "dl.queue"),
            exchange = @Exchange(name = "dl.direct"),//不写type默认是direct交换机
            key = "dlRoutingKey"
    ))
    public void listenDlQueue(String message) {
        System.err.println("接收到 dl.queue的延迟消息：" + message + " " + LocalDateTime.now());
    }


//    @RabbitListener(bindings = @QueueBinding(
//            value = @Queue(name = "delay.queue"),
//            exchange = @Exchange(name = "delay.direct", delayed = "true"),
//            key = "delay"
//    ))
//    public void listenDelayExchange(String message) {
//        System.err.println("接收到 delay.queue的延迟消息：" + message + " " + LocalDateTime.now());
//    }
}
